var app = new Vue({
    el:"#app",
    data:{
        // 页面中需要使用到的数据，键值对
        handline:null,
        user_id: sessionStorage.user_id || localStorage.user_id,
        token: sessionStorage.token || localStorage.token,
        concent:null,
        news:null,
        ordering2:'like-count',
        page:1,
        page_size:5,
        complains:[],

    },
    mounted:function () {

        var id= get_query_string('id',null)
        if(id==null) {
            location.href = '/headline-logined.html'
                } else {
            axios.get(HOST+'handline/'+ id )
            .then(response => {
            this.handline=response.data
        })

}
            // axios.get(HOST + 'newcol/')
            //      .then(response => {
            //         this.status = response.data
            //      })
        axios.get(HOST+'complains/',{
                params:{
                    ordering :this.ordering2,
                    page: this.page,
                    page_size: this.page_size,
                },
                // withCredentials:true
            })
                .then(response => {
                    // var complains = response.data.results;
                    this.complains = response.data.results;
                    // for (var i=0;i<4;i++){
                    //     this.complains[i] = complains[i]
                    // }
                })

    },
    methods: {

        get_new_id: function (id) {
            alert(id)

            axios.get(HOST + 'newcol/'+id,{
                    // 向后端传递JWT token的方法

                    headers: {
                        'Authorization': 'JWT ' + this.token
                    },
                    responseType: 'json',
                    // withCredentials: true
                }
            )

                .then(response => {
                    console.log(response)
                    alert(response.data.message)

                    this.status = response.data.results
                })

        },

        get_user:function (id){
            alert(id)

            axios.post(HOST + 'newsfollow/'+id,{},{
                    // 向后端传递JWT token的方法

                    headers: {
                        'Authorization': 'JWT ' + this.token
                    },
                    responseType: 'json',
                    // withCredentials: true
                }
            )

                .then(response => {
                    console.log(response)
                    alert(response.data.message)

                    this.follow = response.data.results
                })

        },
        // get_comment:function (id){
        //     alert(id)
        //
        //     axios.post(HOST + 'newscomment/'+id,{
        //             content:this.content,
        //             news:id,
        //
        //         },{
        //             // 向后端传递JWT token的方法
        //
        //             headers: {
        //                 'Authorization': 'JWT ' + this.token
        //             },
        //             responseType: 'json',
        //             // withCredentials: true
        //         }
        //     )
        //
        //         .then(response => {
        //             console.log(response)
        //
        //         })
        //
        // },
        get_hot_complains:function () {
            axios.get(HOST + 'complains/',{
                params:{
                    ordering :this.ordering2,
                    page: this.page,
                    page_size: this.page_size,
                },
                withCredentials:true
            })
                .then(response => {
                    this.complains = response.data.results;
                    location.href='./spit-index.html';

                })

        }


        // 需要用到的函数，键值对 ，键是名称，值是匿名函数
    },


    })